import React, { useEffect } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { Spin } from 'antd';

const Redirect: React.FC = () => {
  const { path } = useParams<{ path: string }>();
  const navigate = useNavigate();

  useEffect(() => {
    if (path) {
      // 解码路径并进行重定向
      const decodedPath = decodeURIComponent(path);
      navigate(decodedPath, { replace: true });
    } else {
      // 如果没有路径参数，重定向到首页
      navigate('/', { replace: true });
    }
  }, [path, navigate]);

  return (
    <div style={{ 
      height: '100vh', 
      display: 'flex', 
      alignItems: 'center', 
      justifyContent: 'center' 
    }}>
      <Spin size="large" />
    </div>
  );
};

export default Redirect;